package com.nondo.rdp.auth.repository;

import com.nondo.rdp.core.domain.Dict;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * 字典Dao,负责操作字典表
 * com.seelyn.superp.core.repository
 *
 * @author linfeng
 * @since 2017/7/30
 */
public interface DictRepository extends JpaRepository<Dict, Long>, JpaSpecificationExecutor<Dict> {

    @Query(value = "from Dict where delFlag='" + Dict.DEL_FLAG_NORMAL + "' and id = :id order by sort")
    Dict findById(@Param("id") Long id);

    @Modifying(clearAutomatically = true)
    @Query(value = "update Dict set delFlag='" + Dict.DEL_FLAG_DELETE + "' where id = ?1")
    int deleteById(Long id);

    @Query(value = "from Dict where delFlag='" + Dict.DEL_FLAG_NORMAL + "' order by sort")
    List<Dict> findAllList();

    @Query("select type from Dict where delFlag='" + Dict.DEL_FLAG_NORMAL + "' group by type")
    List<String> findTypeList();

}
